<template>
	<view class="contain">
		<view class="title">
			成员（{{students.length}}人）
		</view>
		<view class="list">

			<view class="item" v-for="(item,index) in students" @click="select(index)">
				<u-avatar shape="square" :src="item.student.avatar"></u-avatar>
				<view class="text">
					{{item.student.name}}
				</view>
				<view class="text" v-if="item.score">
					{{item.score}}
				</view>
				<view class="text" v-else>
					未录入
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/api/index.js'; // 引入api
	export default {
		data() {
			return {
				id: -1,
				complete: false,
				students: [

				],
			};
		},
		onLoad(options) {
			let id = options['id']
			this.id = id
			let token = uni.getStorageSync('token')
			api.getTeacherClassByID(token, id).then((res) => {
				if (res.code === 1) {
					let classItem = res.data
					this.complete = classItem.complete
					let students = []
					for (let i = 0; i < classItem.students.length; i++) {
						let student = classItem.students[i]
						students.push(student)
					}
					console.log(classItem)
					this.students = students
				} else if (res.code === 0) {
					uni.showModal({
						content: res.errors
					})
				}
			}).catch(() => {
				uni.showModal({
					content: "异常",
					showCancel: false,
					success() {
						uni.navigateBack({

						})
					}
				})
			})
		},
		methods: {
			select(index) {
				let studentId = this.students[index].student.id;
				// console.log(studentId)
				console.log(`student?studentId=${studentId}&selectId=${this.id}`)
				uni.navigateTo({
					url: `student?studentId=${studentId}&selectId=${this.id}&complete=${this.complete}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.contain {
		.title {
			color: #8F939C;
			background-color: #D8D8D8;
			font-size: 32rpx;
			height: 40px;
			line-height: 40px;
			padding: 0 40rpx;
		}

		.list {
			.item {
				height: 70px;
				line-height: 70px;
				font-size: 35rpx;
				padding: 0 40rpx;
				border-bottom: #D8D8D8 1rpx solid;
				display: flex;
				flex-direction: row;
				align-items: center;

				.text {
					margin-left: 40rpx;
					width: 300rpx;
				}
			}
		}
	}
</style>
